home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / drawer.zip / BUTTON.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-04  |  2KB  |  87 lines

  1.  
  2. unit Buttons;
  3.  
  4. interface
  5.  
  6. uses MSGraph, Shape;
  7.  
  8. type
  9.     Button =    object
  10.                     x, y    : word;        { position }
  11.                     xe, ye  : word;        { extent   }
  12.                     color   : word;     { color    }
  13.                     bRect   : boolean;  { show rectangle? }
  14.                     data    : shape;    { what to show in button }
  15.                     procedure Initialize( x, y, xe, ye, color : word; bRect : boolean; s : shape);
  16.                     procedure Draw;
  17.                     procedure Erase;
  18.                     procedure Select;
  19.                     procedure UnSelect;
  20.                     function  PtInRegion( px, py : word) : boolean;
  21.                 end;
  22.  
  23. implementation
  24.  
  25. procedure Button.Initialize( x, y, xe, ye, color : word; bRect : boolean; s : shape);
  26. const
  27.     XMARGIN = 4;
  28.     YMARGIN = 4;
  29. begin
  30.     self.x  := x;
  31.     self.y  := y;
  32.     self.xe := xe;
  33.     self.ye := ye;
  34.     self.color := color;
  35.     self.bRect := bRect;
  36.     self.data := s;
  37.     if s<>NIL then
  38.         s.initialize( x+XMARGIN, y+YMARGIN, xe-(XMARGIN+XMARGIN), ye-(YMARGIN+YMARGIN), color);
  39. end;
  40.  
  41. procedure Button.Draw;
  42. begin
  43.     with self do begin
  44.         if self.bRect then begin
  45.             _SetColor(color);
  46.             _SetWriteMode(_GPSET);
  47.             _Rectangle(_GBORDER, x, y, x+xe, y+ye);
  48.             end;
  49.         if data<>NIL then data.Draw;
  50.         end;
  51. end;
  52.  
  53. procedure Button.Erase;
  54. begin
  55.     with self do begin
  56.         _SetColor(0);
  57.         _Rectangle(_GFILLINTERIOR, x, y, x+xe, y+ye);
  58.         end;
  59. end;
  60.  
  61. procedure Button.Select;
  62. begin
  63.     with self do begin
  64.         _SetColor(color);
  65.         _SetWriteMode(_GXOR);
  66.         _SetLineStyle($FFFF);
  67.         _Rectangle(_GBORDER, x+1, y+1, x+xe-1, y+ye-1);
  68.         _Rectangle(_GBORDER, x+2, y+2, x+xe-2, y+ye-2);
  69.         end;
  70. end;
  71.  
  72. procedure Button.UnSelect;
  73. begin
  74.     self.Select;
  75. end;
  76.  
  77.  
  78. function Button.PtInRegion( px, py : word) : boolean;
  79. begin
  80.     with self do
  81.         PtInRegion :=    (px>=x) and (px<=(x+xe)) and
  82.                         (py>=y) and (py<=(y+ye));
  83. end;
  84.  
  85. begin
  86. end.
  87.